<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@3.2.38/dist/vue.global.min.js"></script>
</head>

<body>
  <div id="app">
    <input type="text" @keyup="caplockChange">
    <p>{{msg}}</p>
  </div>
  <script>
    Vue.createApp({
      data() {
        return {
          msg: '',
          isCap: false
        }
      },
      methods: {
        caplockChange(e) {
          if (e.keyCode == 20) {
            if (!this.isCap) {
              this.msg = '当前已切换为大写模式!'
              this.isCap = !this.isCap
            }
            else {
              this.msg = ''
              this.isCap = !this.isCap
            }
          }
        }
      }
    }).mount('#app')
  </script>
</body>

</html>